//
//  AllOrderViewController.m
//  何五路
//
//  Created by _ADY on 15/7/16.
//  Copyright (c) 2015年 _ADY. All rights reserved.
//

#import "AllOrderViewController.h"
#import "ShopsViewController.h"

@interface AllOrderViewController ()

@end

static LoadingView *loading = nil;
#define Allorderhight1 40
#define Allorderhight2 192/2
#define Allorderhight3 40
@implementation AllOrderViewController
@synthesize mTableView,dic,allString;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;
    
    mTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, screenMySize.size.width, screenMySize.size.height) style:UITableViewStyleGrouped];
    mTableView.delegate = self;
    mTableView.dataSource = self;
    mTableView.sectionHeaderHeight = 0.0;
    mTableView.sectionFooterHeight = 0.0;
    mTableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:mTableView];
    
    UIView *v = [[UIView alloc] initWithFrame:CGRectZero];//清除多余分割线
    [mTableView setTableFooterView:v];
    
    __weak __typeof(self) weakSelf = self;
    
    mTableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf loadNewData];
    }];
    mTableView.footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    pageForNumber = 1;
    
}

-(void)setLoading
{
    loading = [[LoadingView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:loading];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.view.backgroundColor =bgColor;
    [mTableView.header beginRefreshing];
    /*OrderStatus
     待支付 Pending = 10,
     待发货 NotShipped = 21,
     已发货 Shipped = 25,
     已完成 Complete = 30,
     已取消 Cancelled = 40,
     
     PaymentStatus
     待处理 Pending = 10,
     授权 Authorized = 20,
     已付款 Paid = 30,
     部分退款 PartiallyRefunded = 35,
     退款 Refunded = 40,
     无效 Voided = 50,
     
     ShippingStatus
     不需要配送 ShippingNotRequired = 10,>
     未发货 NotYetShipped = 20,
     部分发货 PartiallyShipped = 25,
     已发货 Shipped = 30,
     已交货 Delivered = 40,
     
     commentStatus
     未评价 1
     已评价 2
     
     SettlementStatus
     未结算 0
     已结算 1
     orderStatus 订单状态（可选）int类型, paymentStatus支付状态（可选）int类型, shippingStatus配送状态（可选）int类型,
     orderNo 订单编号（可选）string类型, commentStatus评论状态（可选）int类型, vendorId店铺id（可选）int类型,
     customerId客户id（可选）int类型, warehouseId仓库id（可选）int类型, settlementStatus结算状态（可选）int类型,
     userName消费者用户名（可选）string类型, shopName店铺名（可选）string类型, nickName消费者昵称（可选）string类型,
     createdFromUtc下单开始时间（可选）时间类型, createdToUtc下单结束时间（可选）时间类型, pageIndex当前页, pageSize页大小*/
}

-(void)upDateTableView
{
    if ((pageForNumber-1)*itemLabel <= [dic count]||pageForNumber ==1)
    {
        NSMutableDictionary *postDic = [[NSMutableDictionary alloc] init];
        if ([allString isEqualToString:@"0"]) {
        }
        else if ([allString isEqualToString:@"1"])
            [postDic setValue:[NSNumber numberWithInt:10] forKey:@"orderStatus"];
        else if ([allString isEqualToString:@"2"])
            [postDic setValue:[NSNumber numberWithInt:25] forKey:@"orderStatus"];
        else if ([allString isEqualToString:@"3"])
        {
             [postDic setValue:[NSNumber numberWithInt:30] forKey:@"orderStatus"];
            [postDic setValue:[NSNumber numberWithInt:1] forKey:@"commentStatus"];
        }
        
        [postDic setValue:[NSNumber numberWithInt:pageForNumber] forKey:@"pageIndex"];
        [postDic setValue:[NSNumber numberWithInt:itemLabel] forKey:@"pageSize"];
        
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
            NSDictionary *ret = [SendService GetSimpleOrders:postDic];
            dispatch_async(dispatch_get_main_queue(), ^{
                
                NSLog(@"订单列表 %@",ret);
                if (ret !=nil)
                {
                    if (pageForNumber == 1)
                    {
                        if (dic != nil)
                        {
                            [dic removeAllObjects];
                            dic = nil;
                        }
                        dic = [[NSMutableArray alloc] init];
                    }
                    for (NSDictionary *pic in [[ret objectForKey:@"Entity"] objectForKey:@"DataList"])
                    {
                        [dic addObject:pic];
                    }
                }
                if (pageForNumber ==1)
                    [mTableView.header endRefreshing];
                else
                    [mTableView.footer endRefreshing];
                [mTableView reloadData];
                
            });
        });
        
    }
    else
    {
        [mTableView.footer noticeNoMoreData];
        [mTableView reloadData];
    }
    
}

- (void)loadNewData
{
    pageForNumber = 1;
    [self upDateTableView];
}
- (void)loadMoreData
{
    pageForNumber++;
    [self upDateTableView];
}

#pragma mark -
#pragma mark Table View DataSource

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    //    if (section == 0)
    //        return 0.001;
    return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return dic.count;
}

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return Allorderhight1;
    }
    else if (indexPath.row == 1) {
       return Allorderhight2;
    }
    else if (indexPath.row == 2) {
        return Allorderhight3;
    }
    
    return Allorderhight1;
}

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"AllorderCell";
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        aTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        aTableView.showsVerticalScrollIndicator = NO;
    }
    int i = (int)[[cell.contentView subviews] count] - 1;
    for(;i >= 0 ; i--)
    {
        [[[cell.contentView subviews] objectAtIndex:i] removeFromSuperview];
    }
    cell.backgroundColor = [UIColor whiteColor];
    
    NSDictionary *mDic = [dic objectAtIndex:indexPath.section];
    NSString *t1String = nil;
    NSString *t2String = nil;
    NSString *t3String = nil;
    int  tagButton = 0;

    if (indexPath.row == 0)
    {
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, 0, screenMySize.size.width-150, Allorderhight1) setTitle:[NSString stringWithFormat:@"%@",[mDic objectForKey:@"ShopName"]] setColor:YES setFont:NO]];
    }
    else if (indexPath.row == 1)
    {
        NSMutableArray *marray = [mDic objectForKey:@"OrderItems"];
        if (marray.count > 1)
        {
            int Hight = 0;
            
            UIScrollView *ta1ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, self.view.bounds.size.width,Allorderhight2)];
            ta1ScrollView.backgroundColor = [UIColor clearColor];
            [ta1ScrollView setPagingEnabled:NO];
            [ta1ScrollView setShowsHorizontalScrollIndicator:NO];
            [cell.contentView addSubview:ta1ScrollView];
//            //解决UIScrollView把uitableviewcell的点击事件屏蔽start
            ta1ScrollView.userInteractionEnabled = NO;
            [ta1ScrollView addGestureRecognizer:ta1ScrollView.panGestureRecognizer];
//            //解决UIScrollView把uitableviewcell的点击事件屏蔽end
            
            [ta1ScrollView setContentSize:CGSizeMake(self.view.bounds.size.width*marray.count/3,Allorderhight2)];
            
            for (int i = 0; i < marray.count; i ++)
            {
                
                UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10+i*(Allorderhight2-15),Hight+10, Allorderhight2-20,Allorderhight2-20)];
                [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[marray objectAtIndex:i] objectForKey:@"ProdcutPictureUrl"]]]];
                bgImageView.contentMode =  UIViewContentModeScaleAspectFit;
                //    bgImageView.contentMode = UIViewContentModeScaleAspectFill;
                [ta1ScrollView addSubview:bgImageView];
                
                UIImageView *bg1ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(9.5+i*(Allorderhight2-15),Hight+9.5, Allorderhight2-19,Allorderhight2-19)];
                [bg1ImageView setImage:[UIImage imageNamed:@"gwckk"]];
                [ta1ScrollView addSubview:bg1ImageView];
                
                if (![[NSString stringWithFormat:@"%@",[[marray objectAtIndex:i] objectForKey:@"Disabled"]] isEqualToString:@"0"]) {
                    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10+i*(Allorderhight2-15),Hight+10+Allorderhight2-40, Allorderhight2-20,20)];
                    titleLabel.text = @"[已下架]";
                    titleLabel.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:labelSize];
                    titleLabel.textColor = [UIColor redColor];
                    titleLabel.textAlignment = 1;
                    titleLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:.4];
                    [ta1ScrollView addSubview:titleLabel];
                }
            }
            
            
        }
        else
        {
            int Hight = 0;
            
            UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,Hight+10, Allorderhight2-20,Allorderhight2-20)];
            [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[marray objectAtIndex:0] objectForKey:@"ProdcutPictureUrl"]]]];
            bgImageView.contentMode =  UIViewContentModeScaleAspectFit;
            //    bgImageView.contentMode = UIViewContentModeScaleAspectFill;
            [cell.contentView addSubview:bgImageView];
            
            UIImageView *bg1ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(9.5,Hight+9.5, Allorderhight2-19,Allorderhight2-19)];
            [bg1ImageView setImage:[UIImage imageNamed:@"gwckk"]];
            [cell.contentView addSubview:bg1ImageView];
            
            [cell.contentView addSubview:[self setFrame:CGRectMake(Allorderhight2, Hight+10, screenMySize.size.width-Allorderhight2-50, Allorderhight2-20) setTitle:[NSString stringWithFormat:@"%@",[[marray objectAtIndex:0] objectForKey:@"ProductName"]] setFont:labelSize setColor:[UIColor blackColor]]];
            
            [cell.contentView addSubview:[self setFrame:CGRectMake(screenMySize.size.width-50,(Allorderhight2-30)/2, 40, 30) setTitle:[NSString stringWithFormat:@"x%@",[[marray objectAtIndex:0] objectForKey:@"Quantity"]] setFont:NO]];
            if (![[NSString stringWithFormat:@"%@",[[marray objectAtIndex:0] objectForKey:@"Disabled"]] isEqualToString:@"0"]) {
                
                UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,Hight+10+Allorderhight2-40, Allorderhight2-20,20)];
                    titleLabel.text = @"[已下架]";
                titleLabel.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:labelSize];
                titleLabel.textColor = [UIColor redColor];
                titleLabel.textAlignment = 1;
                titleLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:.4];
                [cell.contentView addSubview:titleLabel];
            }
            
        }
    }
    else if (indexPath.row == 2)
    {
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, 0, screenMySize.size.width-150, Allorderhight3) setTitle:[NSString stringWithFormat:@"实付款:¥%@",[mDic objectForKey:@"OrderTotal"]] setColor:YES setFont:YES]];
    }
    

    if ([[NSString stringWithFormat:@"%@",[mDic objectForKey:@"OrderStatusId"]] isEqualToString:@"Complete"])
    {
        if (indexPath.row == 0)
        {
            UIImageView *bg1ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(screenMySize.size.width-90,15, 65,65)];
            [bg1ImageView setImage:[UIImage imageNamed:@"orderWc"]];
            [cell.contentView addSubview:bg1ImageView];
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setFrame:CGRectMake(screenMySize.size.width-10-35/2,(Allorderhight1-35/2)/2, 35/2,35/2)];
            [button setBackgroundImage:[UIImage imageNamed:@"orderLjx"] forState:UIControlStateNormal];
            button.tag = 8000+indexPath.section;
            [button addTarget:self action:@selector(setButtonTag:) forControlEvents:UIControlEventTouchUpInside];
            [cell.contentView addSubview:button];
            
        }
        else if (indexPath.row == 1)
        {
            UIImageView *bg1ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(screenMySize.size.width-90,-25, 65,65)];
            [bg1ImageView setImage:[UIImage imageNamed:@"orderWc"]];
            [cell.contentView addSubview:bg1ImageView];
        }
        else if (indexPath.row == 2)
        {
            tagButton = 1000+indexPath.section;
            t3String = @"评价晒单";

        }

    }
    else if ([[NSString stringWithFormat:@"%@",[mDic objectForKey:@"OrderStatusId"]] isEqualToString:@"NotShipped"])
    {
        if (indexPath.row == 0)
        {
            t1String = @"待发货";
        }
        else if (indexPath.row == 2)
        {
            tagButton = 2000+indexPath.section;
            t2String = @"提醒发货";
            t3String = @"确认收货";
        }
        
    }
    else if ([[NSString stringWithFormat:@"%@",[mDic objectForKey:@"OrderStatusId"]] isEqualToString:@"Shipped"])
    {
        if (indexPath.row == 0)
        {
            t1String = @"已发货";
        }
        else if (indexPath.row == 2)
        {
            tagButton = 3000+indexPath.section;
            t2String = @"订单追踪";
            t3String = @"确认收货";
        }
    }
    else if ([[NSString stringWithFormat:@"%@",[mDic objectForKey:@"OrderStatusId"]] isEqualToString:@"Pending"])
    {
        if (indexPath.row == 0)
        {
            t1String = @"等待付款";
        }
        else if (indexPath.row == 2)
        {
            tagButton = 4000+indexPath.section;
            t3String = @"去支付";
        }
        
    }
    else if ([[NSString stringWithFormat:@"%@",[mDic objectForKey:@"OrderStatusId"]] isEqualToString:@"Cancelled"])
    {
        if (indexPath.row == 0)
        {
            t1String = @"已取消";
        }
    }
    if (t1String.length != 0)
        [cell.contentView addSubview:[self setFrame:CGRectMake(screenMySize.size.width-100, 0, 90, Allorderhight3) setTitle:t1String setFont:NO]];
    
    if (tagButton/1000 == 2 ||  tagButton/1000 == 3)
    {
        if (t2String.length != 0) {
            UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
            [button1 setFrame:CGRectMake(screenMySize.size.width-10-139/2-139/2-10, (Allorderhight3-49/2)/2, 139/2, 49/2)];
            [button1 setBackgroundImage:[UIImage imageNamed:@"orderb1_btn"] forState:UIControlStateNormal];
            button1.tag = tagButton;
            [button1 setTitle:t2String forState:UIControlStateNormal];
            button1.titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize];
            [button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [button1 addTarget:self action:@selector(setButtonTag:) forControlEvents:UIControlEventTouchUpInside];
            [cell.contentView addSubview:button1];
        }

        if (t3String.length != 0)
        {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setFrame:CGRectMake(screenMySize.size.width-10-139/2, (Allorderhight3-49/2)/2, 139/2, 49/2)];
            [button setBackgroundImage:[UIImage imageNamed:@"orderb_btn"] forState:UIControlStateNormal];
            button.tag = 5000+indexPath.section;
            [button setTitle:t3String forState:UIControlStateNormal];
             button.titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(setButtonTag:) forControlEvents:UIControlEventTouchUpInside];
            [cell.contentView addSubview:button];
        }


    }
    else
    {
        if (t3String.length != 0)
            [cell.contentView addSubview:[self setButton:t3String setFrame:CGRectMake(screenMySize.size.width-10-139/2, (Allorderhight3-49/2)/2, 139/2, 49/2) setTag:tagButton]];
    }

    
    /*OrderStatus
     待支付 Pending = 10,
     待发货 NotShipped = 21,
     已发货 Shipped = 25,
     已完成 Complete = 30,
     已取消 Cancelled = 40,
     
     commentStatus
     未评价 1
     已评价 2
     
     PaymentStatus
     待处理 Pending = 10,
     授权 Authorized = 20,
     已付款 Paid = 30,
     部分退款 PartiallyRefunded = 35,
     退款 Refunded = 40,
     无效 Voided = 50,*/
    return cell;
}

-(void)setButtonTag:(id)sender
{
    int type = ((UIButton*)sender).tag;
    alertTag = type;
    if (type/1000 == 1)//评价晒单
    {
        YEvaluationViewController *details = [[YEvaluationViewController alloc] init];
        details.hidesBottomBarWhenPushed = YES;
        details.aDic = [dic objectAtIndex:type%1000];
        [self.navigationController pushViewController:details animated:YES];
    }
    else if (type/1000 == 2)//提醒发货
    {
        
    }
    else if (type/1000 == 3)//订单追踪
    {
        
    }
    else if (type/1000 == 4)//去支付
    {
        PayViewController *details = [[PayViewController alloc] init];
        details.hidesBottomBarWhenPushed = YES;
        details.allString = [[dic objectAtIndex:type%1000] objectForKey:@"OrderTotal"];
        details.orderId = [[dic objectAtIndex:type%1000] objectForKey:@"Id"];
        [self.navigationController pushViewController:details animated:YES];
    }
    else if (type/1000 == 5)//确认收货
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"是否确定收货？"  delegate:self cancelButtonTitle:@"否" otherButtonTitles:@"是",nil];
        alert.tag = 5;
        [alert show];
        

    }
    else if (type/1000 == 8)//删除
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"是否确定删除订单？"  delegate:self cancelButtonTitle:@"否" otherButtonTitles:@"是",nil];
        alert.tag = 8;
        [alert show];

    }
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
     if (buttonIndex == 1)
     {
         NSMutableDictionary *postDic = [[NSMutableDictionary alloc] init];
         
         [postDic setValue:[NSNumber numberWithInt:[[NSString stringWithFormat:@"%@",[[dic objectAtIndex:alertTag%1000] objectForKey:@"Id"]] intValue]] forKey:@"orderId"];
         
         loading = [[LoadingView alloc] initWithFrame:self.view.frame];
         [self.view addSubview:loading];
         
         if (alertView.tag == 5)
         {
             dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
                 NSDictionary *ret = [SendService SetAsDelivered:postDic];
                 dispatch_async(dispatch_get_main_queue(), ^{
                     
                     [loading closeLoading];
                     NSLog(@"确认收货 %@",ret);
                     if ([[NSString stringWithFormat:@"%@",[ret objectForKey:@"Result"]] isEqualToString:@"success"])
                     {
                         [SendService alerViewMessage:@"确认收货成功。"];
                         pageForNumber = 1;
                         [mTableView.header beginRefreshing];
                         
                     }
                     else
                         [SendService alerViewMessage:[ret objectForKey:@"Message"]];
                 });
             });
         }
         else if (alertView.tag == 8)
         {
             dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
                 NSDictionary *ret = [SendService SetCustomerDeleteStatus:postDic];
                 dispatch_async(dispatch_get_main_queue(), ^{
                     
                     [loading closeLoading];
                     NSLog(@"删除订单 %@",ret);
                     if ([[NSString stringWithFormat:@"%@",[ret objectForKey:@"Result"]] isEqualToString:@"success"])
                     {
                         [SendService alerViewMessage:@"删除订单成功。"];
                         pageForNumber = 1;
                         [mTableView.header beginRefreshing];
                     }
                     else
                         [SendService alerViewMessage:[ret objectForKey:@"Message"]];

                 });
             });
         }
     }

}


-(UIButton*)setButton:(NSString*)title setFrame:(CGRect)bFrame setTag:(int)bTag
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setFrame:bFrame];
    [button setBackgroundImage:[UIImage imageNamed:@"orderKk"] forState:UIControlStateNormal];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[UIColor colorWithRed:242/255.0 green:84/255.0 blue:85/255.0 alpha:1] forState:UIControlStateNormal];
     button.titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize];
    button.tag = bTag;
    [button addTarget:self action:@selector(setButtonTag:) forControlEvents:UIControlEventTouchUpInside];
    
    return button;
}

-(UILabel*)setFrame:(CGRect)frame setTitle:(NSString*)title setFont:(int)font setColor:(UIColor*)myColor
{
    title = [title stringByReplacingOccurrencesOfString:@"<null>" withString:@""];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:frame];
    if (title != nil)
        titleLabel.text = [NSString stringWithFormat:@"%@",title];
    titleLabel.textAlignment = 0;
    titleLabel.numberOfLines = 0;
    titleLabel.font = [UIFont fontWithName:@"Arial" size:font];
    titleLabel.textColor = myColor;
    return titleLabel;
}

-(UILabel*)setFrame:(CGRect)frame setTitle:(NSString*)title setFont:(BOOL)font
{
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:frame];
    if (title != nil)
        titleLabel.text = [NSString stringWithFormat:@"%@",title];
    titleLabel.textAlignment = 2;
    if (font)
        titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize];
    else
        titleLabel.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:labelSize];
    titleLabel.textColor = [UIColor redColor];
    
    return titleLabel;
}

-(UILabel*)setFrame:(CGRect)frame setTitle:(NSString*)title setColor:(BOOL)black setFont:(BOOL)font
{
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:frame];
    if (title != nil)
        titleLabel.text = [NSString stringWithFormat:@"%@",title];
    titleLabel.textAlignment = 0;
    titleLabel.numberOfLines = 0;
    if (font)
        titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize];
    else
        titleLabel.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:labelSize];
    if (black)
        titleLabel.textColor = [UIColor blackColor];
    else
        titleLabel.textColor = [UIColor redColor];
    
    return titleLabel;
}


- (void)tableView:(UITableView *)table1View didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        NSDictionary *mDic = [dic objectAtIndex:indexPath.section];
        ShopsViewController *details = [[ShopsViewController alloc] init];
        details.shopsId = [NSString stringWithFormat:@"%@",[mDic objectForKey:@"ShopId"]];
        details.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:details animated:YES];
    }
    else if (indexPath.row == 1)
    {
        NSInteger aaInt = 0;
        NSDictionary *mDic = [dic objectAtIndex:indexPath.section];
        if ([[NSString stringWithFormat:@"%@",[mDic objectForKey:@"OrderStatusId"]] isEqualToString:@"Complete"])
        {
            aaInt = 0;
            //完成
        }
        else if ([[NSString stringWithFormat:@"%@",[mDic objectForKey:@"OrderStatusId"]] isEqualToString:@"NotShipped"])
        {
            aaInt = 1;
            //待发货
            
        }
        else if ([[NSString stringWithFormat:@"%@",[mDic objectForKey:@"OrderStatusId"]] isEqualToString:@"Shipped"])
        {
            aaInt = 1;
            //已发货
        }
        else if ([[NSString stringWithFormat:@"%@",[mDic objectForKey:@"OrderStatusId"]] isEqualToString:@"Pending"])
        {
            aaInt = 2;
            //去支付
        }
        else if ([[NSString stringWithFormat:@"%@",[mDic objectForKey:@"OrderStatusId"]] isEqualToString:@"Cancelled"])
        {
            aaInt = 3;
            //已取消
        }
        
        ShopsMentViewController *details = [[ShopsMentViewController alloc] init];
        details.idStr = [[dic objectAtIndex:indexPath.section] objectForKey:@"Id"];
        details.shopsInt = aaInt;
        details.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:details animated:YES];

    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
